
 GLSLProgram = function( programName, vertexShader, fragmentShader)
{
	/************************************/
	/*			Properties				*/	
	/************************************/

		this.m_Program;				/*!<	Store the Id returned by the gl.createProgram function							*/
		this.m_Name;				/*!<	Name use to Idenfitied the current GLSLProgram									*/
		this.m_ID;					/*!<	Unique Identifier for the GLSLProgram, can be also used for identification,	and rapid acces
											throug the GLSLProgram.Programs container		*/
	
		this.m_Uniforms		=	new Array();	/*!< Store GLSLID to shaders uniform values				*/
		this.m_Shaders 		= 	new Array();	/*!< Store Shaders linked to current GLSLProgram		*/
		
	/************************************/
	/*			Constructor				*/	
	/************************************/
	
	try
	{	
		console.log(vertexShader);
		console.log(fragmentShader);
		
		if(vertexShader == undefined )
		{
			throw(1);
		}
		if(fragmentShader==undefined)
		{
			throw(2);
		}
		
		//	We store its shaders
		this.m_Shaders.push(vertexShader);
		this.m_Shaders.push(fragmentShader);

		//We create the program
		this.m_Program 	= gl.createProgram();	
		
		console.log(this.m_Program);
		console.log(vertexShader);
		
		//	We give the programs its shaders	
	    gl.attachShader(this.m_Program, this.m_Shaders[0].shader);
        gl.attachShader(this.m_Program, this.m_Shaders[1].shader);
		
		console.log("attached");
		
		//	We "Link" them together
        gl.linkProgram(this.m_Program);
		console.log(this.m_Program);
		if(!gl.getProgramParameter(this.m_Program, gl.LINK_STATUS))
		{
			throw(3);
		}
		
		//	If every steps succeed, we give the current Program a new ID
		this.m_ID	=	GLSLProgram.PeekID();

		//	Then we define it's name
		if(programName==undefined)
		{
			this.m_Name="Default"+this.m_ID;
		}
		this.m_Name = programName;
		this.GetUniforms();
	}
	catch(e)
	{
		switch(e)
		{
			case 1	:
				alert("Error 1 : Vertex Shader undefined ");
			break;
			
			case 2 : 
				alert("Error 2 : Fragment Shader undefined ");
			break;
			
			case 3 : 
				alert("Error 2 : Program's Linker Error ");
			break;
			
			default : 
				alert("Error 404 : Problem at Program Initialization");
			break;
		}
	}
}


GLSLProgram.prototype.GetUniforms = function()
{
	this.m_Uniforms.push(gl.getUniformLocation(this.m_Program, "u_ModelMatrix"));
	this.m_Uniforms.push(gl.getUniformLocation(this.m_Program, "u_ViewMatrix"));
	this.m_Uniforms.push(gl.getUniformLocation(this.m_Program, "u_ProjectionMatrix"));
	this.m_Uniforms.push(gl.getUniformLocation(this.m_Program, "u_Texture0"));
	
	this.m_Uniforms.push(gl.getUniformLocation(this.m_Program, "u_OffsetX"));
	this.m_Uniforms.push(gl.getUniformLocation(this.m_Program, "u_OffsetY"));
	this.m_Uniforms.push(gl.getUniformLocation(this.m_Program, "u_ScaleX"));
	this.m_Uniforms.push(gl.getUniformLocation(this.m_Program, "u_ScaleY"));

}

GLSLProgram.s_IDCount	=	0;
GLSLProgram.PeekID		=	function()
{

	var currentId=GLSLProgram.s_IDCount;
	GLSLProgram.s_IDCount +=1;
	return currentId;
}
GLSLProgram.prototype.Use	=	function()
{
	gl.useProgram(this.m_Program);
}

GLSLProgram.Disable = function()
{
	gl.useProgram(0);
}

/*!	brief List of GLSL Programs used by our application	*/
GLSLProgram.Programs	= new Array();

GLSLProgram.Default;

/*!	brief Create a new program and stored it directly in our container	*/
GLSLProgram.New		=	function( programName, vertexShader, fragmentShader)
{
	GLSLProgram.Programs.push(new GLSLProgram(programName, vertexShader, fragmentShader));
	GLSLProgram.Default = GLSLProgram.Programs[GLSLProgram.Programs.length-1];
	
	Attributes.m_Index.push(gl.getAttribLocation(GLSLProgram.Default.m_Program, "a_Position"));
	Attributes.m_Index.push(gl.getAttribLocation(GLSLProgram.Default.m_Program, "a_Color"));
	Attributes.m_Index.push(gl.getAttribLocation(GLSLProgram.Default.m_Program, "a_Normal"));
	Attributes.m_Index.push(gl.getAttribLocation(GLSLProgram.Default.m_Program, "a_TexCoord0"));
}



